$:.push File.expand_path(File.dirname(__FILE__))

require 'socket'
require 'uri'
require 'digest/md5'
require 'timeout'
require 'thread'

%w(url headers_hash handshake_response protocol_base websocket).each { |n| require "ws_client/#{n}" }

%w(protocol_factory).each { |n| require "ws_client/versions/#{n}" }
%w(handshake close framing frame protocol).each { |n| require "ws_client/versions/ietf00/#{n}" }

module WsClient
	class WebSocketError < StandardError; end
	class HandshakeError < WebSocketError; end
	#class FrameError < StandardError; end
	class ClosingError < WebSocketError; end
	#class SocketError < StandardError; end
	
	String.class_eval do
		def utf8(options = {})
			options = { :invalid => :replace, 
				:undef => :replace, :replace => "\uFFFD" }.update(options)
		
			self.encode('utf-8', options)
		end
	end
end
